home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 201 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  58 lines

  1. Newsgroups: comp.lang.c
  2. Path: yarrow.wt.com.au!hawk!hawk!wayne
  3. From: wayne@adied.oz.au (Wayne Elliott)
  4. Subject: Array Parameters
  5. Message-ID: <wayne.820650643@hawk>
  6. Organization: ADI Ltd. - Systems Division
  7. Date: Wed, 3 Jan 1996 06:30:43 GMT
  8.  
  9. Can anyone fill me in on whats wrong with the following snippet of
  10. code. Basically I'm trying to pass and use a multi-dimensional
  11. array.
  12.  
  13. -----------------------------------------------------------------
  14.  
  15. /* Test passing of array parameters */
  16.  
  17. #include <stdio.h>
  18.  
  19. char map [][8] =
  20. {
  21.   "abcdef",
  22.   "ghijkl",
  23.   "mnopqr"
  24. };
  25.  
  26. void test(int num, char ** maps)
  27. {
  28.   int i;
  29.   for(i=0;i<num;i++)
  30.     if(maps[i])
  31.       printf("%04d %s\n", i, maps[i]);
  32.     else
  33.       printf("%04d NULL\n", i);
  34. }
  35.  
  36. int main()
  37. {
  38.   test(3, (char **) map);
  39.   return 0;
  40. }
  41.  
  42. -----------------------------------------------------------------
  43.  
  44. At home this only finds the first element (map[0]).
  45. At work this gives a core dump.
  46. Using pointer arithmetic (maps+i) produced something like
  47.  
  48. 0000 abcedf
  49. 0001 ef
  50. 0002 ghijkl
  51.  
  52. It's all rather comfusing!
  53. Any clues?  How should I be doing this?
  54.  
  55. Thanks 
  56. Wayne Elliott
  57.   
  58.